<template>
    <div style="text-align: center;margin: auto">
<!--        <div style="height: 50px">-->
<!--            <el-button type="warning" plain-->
<!--                       @click="" style="float: left">新增</el-button>-->
<!--        </div>-->

        <el-table
            border
            :data="shopManagers"
                  style="width:1450px;border-radius: 15px">
            <!--<el-table-column
                    label="头像"
                    prop="picSrc" >
                <template slot-scope="scope">
                    <el-image :src="scope.row.picSrc" style="width: 50px;height: 50px" v-if="scope.row.picSrc!==null"/>
                    <span :src="scope.row.picSrc" style="width: 50px;height: 50px" v-if="scope.row.picSrc===null">暂无</span>
                </template>
            </el-table-column>-->
            <el-table-column
                align="center"
                    label="用户名"
                    prop="name" style="width: 50px" >
            </el-table-column>
            <el-table-column
                align="center"
                    label="姓名"
                    prop="name" style="width: 50px" >
            </el-table-column>
            <el-table-column
                align="center"
                    label="手机号"
                    prop="phone" >
            </el-table-column>
            <el-table-column
                align="center"
                    label="身份证号"
                    prop="identityNumber" >
            </el-table-column>
            <el-table-column
                align="center"
                    label="状态"
                    prop="stat" >
                <template slot-scope="scope">
                    <span v-if="scope.row.stat===1">正常</span>
                    <span v-if="scope.row.stat===0">冻结</span>
                </template>
            </el-table-column>

            <el-table-column
                    align="center" >
                <template slot="header" slot-scope="scope">
                   <span style="text-align: center">操作</span>
                </template>
                <template slot-scope="scope" style="width: 100px">
                    <el-button
                            size="mini"
                            @click="edit(scope.row)" style="background-color: #fced6e;width: 50px;display: inline-block">修改</el-button>
                    <el-button
                            size="mini"
                            type="warning"
                            @click="freeze(scope.row)" style="width: 50px;display: inline-block" v-if="scope.row.stat===1">冻结</el-button>
                    <el-button
                            size="mini"
                            type="success"
                            @click="freeze(scope.row)" style="width: 50px;display: inline-block" v-if="scope.row.stat===0">开启</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--点击修改后的弹窗-->
        <el-dialog title="管理人员信息" :visible.sync="editDialogVisible" style="line-height: 15px">
            <el-form :model="shopManagersInfo" status-icon :rules="goodRules" ref="shopManagersInfo" style="text-align: left">
                <el-form-item label="  用户名" :label-width="formLabelWidth" prop="username">
                    <el-input v-model="shopManagersInfo.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密    码" :label-width="formLabelWidth" prop="password">
                    <el-input v-model="shopManagersInfo.password" autocomplete="off"></el-input>
                </el-form-item>

            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="flush" style="background-color: #fced6e">取 消</el-button>
                <el-button style="background-color: #009be2" @click="save">保 存</el-button>
            </span>
        </el-dialog>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "ShopManagerManager",
        created(){
            this.axios.get("http://localhost:8084/findAllShopManagerByPage",{
                params:{
                    currentPage:this.currentPage,
                    pageSize:this.pageSize
                }
            }).then(resp=>{
                console.log(resp.data);
                this.shopManagers = resp.data.shopManagers;
                this.total = resp.data.count;
            })
        },
        data(){
            return{
                userInfo:'',
                search:'',
                shopManagers:[
                    {
                        id:"",
                        username:'123',
                        phone:'',
                        name:'',
                        identityNumber:'',
                        stat:''
                    }
                ],
                freezeshopManagers:{
                            smid:'',
                            stat:''
                },
                shopManagersInfo:{
                    smid:"",
                    username:'',
                    password:'',
                    phone:'',
                    name:'',
                    identityNumber:'',
                    stat:'',
                    rid:''
                },
                pageSize:5,
                total: 0,
                currentPage: 1,
                pageSizes:[1,2,3,4,5,6,7,8,9,10],
                //控制弹窗是否显示
                editDialogVisible: false,
            }
        },
        methods:{
            handleSizeChange(val) {
                this.pageSize = val;
                const that = this;
                this.axios.get("http://localhost:8084/findAllShopManagerByPage",{
                    params:{
                        currentPage:this.currentPage,
                        pageSize:this.pageSize
                    }
                }).then(resp=>{
                    console.log(resp.data);
                    this.shopManagers = resp.data.shopManagers;
                    this.total = resp.data.count;
                })
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                const that = this;
                this.axios.get("http://localhost:8084/findAllShopManagerByPage",{
                    params:{
                        currentPage:this.currentPage,
                        pageSize:this.pageSize
                    }
                }).then(resp=>{
                    console.log(resp.data);
                    this.shopManagers = resp.data.shopManagers;
                    this.total = resp.data.count;
                })
            },
        freeze(item){
            console.log(item);
            var msg='冻结';
            var statTemp=0;//默认正常
            if(item.stat===0){//冻结状态改成正常
                statTemp=1;
                msg='开启';
            }    
            this.$confirm("确定要"+msg+"此类别吗？", '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'info'
            }).then(() => {
                this.freezeshopManagers.smid = item.smid;
                this.freezeshopManagers.stat = statTemp;
                console.log(this.freezeshopManagers);
                this.axios.post("http://localhost:8084/changeShopManagerStat", this.freezeshopManagers).then(resp => {
                    if (resp.data === "success") {
                        this.$message({
                            message: msg+"成功！！！",
                            type: 'success'
                        });
                    } else {
                        this.$message({
                            message: msg+"失败！！！",
                            type: 'warning'
                        });
                    }
                  this.flush();
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            })
        },
        /*取消保存*/
        flush(){
                this.dialogVisible = false;
                this.$router.push({
                    name:"blank",
                    params:{
                        url:"shopManagerManager"
                    }
                })
            },
        edit(item){
            console.log(item);
            this.editDialogVisible = true;
            this.shopManagersInfo.smid = item.smid;
            this.shopManagersInfo.username = item.username;
            this.shopManagersInfo.password = item.password;
        },
        /*保存修改*/
        save() {
                console.log(this.shopManagersInfo);
                this.$refs['shopManagersInfo'].validate((valid) => {
                    if (valid) {
                        this.$confirm("确定要保存修改吗？", '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'info'
                        }).then(() => {
                            console.log(this.shopManagersInfo);
                            this.axios.post("http://localhost:8084/changeShopManagerStat", this.shopManagersInfo).then(resp => {
                                if (resp.data === "success") {
                                    this.$message({
                                        message: "保存成功！！！",
                                        type: 'success'
                                    });
                                    this.flush();
                                } else {
                                    this.$message({
                                        message: "保存失败！！！",
                                        type: 'warning'
                                    });
                                    this.flush();
                                }
                            })
                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '已取消'
                            });
                        })
                    } else {
                        return false;
                    }
                })
            },
        }
    }
</script>

<style scoped>
    .el-table{
        line-height: 50px;
        margin: auto;
    }
</style>
